CONTENTS | INDEX | PREV | NEXT
gets
NAME
gets - get a line from stdin
SYNOPSIS
#include <stdio.h>
char *ptr = gets(buf);
char *buf;
FUNCTION
gets() gets a line from stdin returning its first argument (buf)
if all went well, NULL if an error or EOF occurs.
gets() stores the line into the specified buffer up to a maximum
of 256 characters (includes 0).
It is common to get confused between gets(), fgets(), puts(), and
fputs(). gets() strips off any newline 'n' and puts() adds one
while fgets() keeps the newline at the end of the line and fputs()
does NOT add one. gets() and puts() work on stdin and stdout
while fgets() and fputs() work on arbitrary file pointers.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
#include <stdio.h>
main()
{
char buf[256];
printf("Enter a line - ");
fflush(stdout);
if (gets(buf) == NULL)
exit(1);
printf("Your line was: %sn", buf);
return(0);
}
INPUTS
char *buf; buffer, must be able to hold 256 characters.
RESULTS
char *ptr; buf if all is well, or NULL if error or EOF
SEE ALSO
gets, puts, fputs, fread, getc, fgetc